$(function() {
	var idLDAP = $( "#idLDAP" ),
		subject = $( "#subject" ),
		mail = $( "#mail" ),
		tips = $( ".validateTips" )
		single=true;
	   
	$( "#bug-report-dialog" ).dialog({
		autoOpen: false,
		resizeable: false,
		height: 580,
		minHeight: 580,
		width: 580,
		minWidth: 580,
		modal: true,
		close: function() {
			$( "#bug-report-dialog" ).children().remove();
		},
		buttons: [{
				id:"cancel",
				tabindex:4,
				text:"Annuler",
				click: function() {
							$( this ).dialog( "close" );
							$( "#bug-report-dialog" ).children().remove();
						}
			},
			{
				id:"submit-bug-report",
				tabindex:3,
				text:"Envoyer",
				click: function() {
					
					var bValid = true;
				
	
					if ( bValid&&single ) {
						single=false;
						$( "#bug-report-dialog" ).append("<div id='progress'><br/><p class='progressbar'>Envoi rapport en cours..</p><div id='progressbar' class='progressbar'/></div></div>");
						$( "#progressbar" ).progressbar({
							value: 100
						});
						
						$.ajax({
							type: 'POST',
							dataType:'json',
							url: "bugReport.htm",
							data: {
								idLDAP : idLDAP.val(),
								subject : subject.val(),
								mail : mail.val()
							},
							error:function(msg){
								tips.text('error').addClass('ui-state-error ui-corner-all');
								$( "#progress" ).remove();
								single=true;
							},
							success: function( data ) {
								single=true;
								if(data.success==true){
									$( "#bug-report-dialog"  ).dialog( "close" );
									$( "#notification-dialog" ).append("<p style='text-align=center;'><img src='/ASOF/img/success.png' style='width:20px ;position: absolute; left: .5em; top: 13%;margin-top: -8px;' /><span style='position: absolute;left:30px'>"+data.message+"</span></p>");
									$( "#notification-dialog" ).dialog("open");
								}else{
									tips.text(data.message).addClass('ui-state-error ui-corner-all');
									$( "#progress" ).remove();
								}
							}
						});
					}
				}
			}
		]
	});
});